import http from "@/api";
import qs from "qs";

/**
 * @name 请求管理模块
 */

// 请求列表
export const findRequests = params => {
  console.log(params)
  return http.post(`/pages/request!findRequests.action`, qs.stringify(params),{ loading: false });
};

// 我提交的请求列表
export const findMyRequests = params => {
  return http.post(`/pages/clientRequest!findRequests.action`, qs.stringify(params), { loading: false });
};

// 过滤器列表
export const findCustomFilter = userName => {
  return http.post(
    `/pages/filter!findCustomFilter.action?queryDTO.filterCategory=request&queryDTO.userName=${userName}`,
    qs.stringify({}),
    { loading: false }
  );
};

// 通过过滤器查询列表
export const findPagerRequestByCustomFilter = params => {
  return http.post(`/pages/request!findPagerRequestByCustomFilter.action`, qs.stringify(params), { loading: false });
};

// 查询自己编辑的过滤器列表-用于再次编辑
export const findMyFilters = userName => {
  return http.post(
    `/pages/filter!findMyFilters.action?queryDTO.filterCategory=request&&queryDTO.userName=${userName}`,
    qs.stringify({}),
    { loading: false }
  );
};

// 获取过滤器信息-用于再次编辑
export const findFilterById = filterId => {
  return http.post(`/pages/filter!findFilterById.action?queryDTO.filterId=${filterId}`, qs.stringify({}), { loading: false });
};

// 保存过滤器
export const filterUpdate = params => {
  return http.post(`/pages/filter!update.action`, qs.stringify(params), { loading: false });
};

// 删除过滤器
export const deleteFilter = id => {
  return http.post(`/pages/filter!delete.action?ids=${id}`, qs.stringify({}), { loading: false });
};

// 新增过滤器
export const saveFilter = params => {
  return http.post(`/pages/filter!save.action`, qs.stringify(params), { loading: false });
};

// 删除请求
export const deleteRequests = params => {
  return http.post(`/pages/clientRequest!deleteRequests.action`, qs.stringify(params));
};

// 请求的详情信息
export const findRequestByIdByClient = params => {
  return http.post(`/pages/clientRequest!findRequestByIdByClient.action`, qs.stringify(params), { loading: false });
};

// 分类列表
export const getCategoryTreeClient = params => {
  return http.post(`/pages/clientRequest!getCategoryTreeClient.action`, qs.stringify(params), { loading: false });
};

// 优先级，紧急度，影响范围，来源，复杂程度
export const findByCode = params => {
  return http.post(`/pages/clientRequest!findByCode.action`, qs.stringify(params), { loading: false });
};

// 请求人列表，技术员列表
export const findPagerUserClient = params => {
  return http.post(`/pages/clientUser!findPagerUserClient.action`, qs.stringify(params), { loading: false });
};

// 新增请求
export const saveRequestClient = (ciIdsText, params) => {
  return http.post(`/pages/request!saveRequest.action?${ciIdsText}`, qs.stringify(params));
};

// 请求编辑保存
export const updateRequest = (ciIdsText, params) => {
  return http.post(`/pages/request!updateRequest.action?${ciIdsText}`, params);
};

// 请求统计
export const countRequest = params => {
  return http.post(`/pages/clientRequest!countRequest.action`, qs.stringify(params), { loading: false });
};

// 我待处理的任务
export const findPagePersonalTasks = params => {
  return http.post(`/pages/jbpm!findPagePersonalTasks.action`, qs.stringify(params), { loading: false });
};

// 批量处理
export const requestBatchClose = params => {
  return http.post("/pages/reqest!requestBatchClose.action", qs.stringify(params), { loading: false });
};

// 详情-任务列表
export const findPagerChangeTask = params => {
  return http.post("/pages/eventTask!findPagerChangeTask.action", qs.stringify(params), { loading: false });
};

// 状态列表
export const requestFlotPieData = params => {
  return http.post("/pages/request!requestFlotPieData.action", qs.stringify(params), { loading: false });
};
//提交邮件回复前验证
export const checkEmail = params => {
  return http.post("/pages/email!testEmail.action", qs.stringify(params), { loading: false });
};
// 邮件回复
export const toEmail = params => {
  return http.post("/pages/email!toEmail.action", qs.stringify(params), { loading: false });
};

// 获取解决方案处理方式选项列表
export const dataDictionaryItemsFindByCode = params => {
  return http.post(
    "/pages/dataDictionaryItems!findByCode.action?dataDictionaryQueryDto.groupCode=offmode",
    qs.stringify(params),
    { loading: false }
  );
};

// 保存解决方案
export const saveSolutions = params => {
  return http.post("/pages/request!saveSolutions.action", qs.stringify(params), { loading: false });
};

// 任务重新指派
export const assignTask = params => {
  return http.post("/pages/request!assignTask.action", qs.stringify(params), { loading: false });
};

// 请求升级成问题，获取数据详情赋值给编辑弹窗
export const showRequestInfo = eno => {
  return http.post(`/pages/request!showRequestInfo.action?eno=${eno}`, qs.stringify({}), { loading: false });
};

// 请求退回/描述完成重新提交/挂起/解除挂起/请求提取
export const requestAction = params => {
  return http.post("/pages/request!requestAction.action", qs.stringify(params), { loading: false });
};

// 开启流程
export const openProcess = params => {
  return http.post("/pages/request!openProcess.action", qs.stringify(params), { loading: false });
};

// 处理完成/指派其他技术员处理
export const processHandle = params => {
  return http.post("/pages/request!processHandle.action", qs.stringify(params), { loading: false });
};

// 删除附件
export const deleteEventAttachment = params => {
  return http.post("/pages/eventAttachment!deleteEventAttachment.action", qs.stringify(params), { loading: false });
};

// 保存请求
export const saveRequest = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}`.includes("eav_")) {
        newobj[header + ".attrVals['" + `${key}` + "']"] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post("" + `/pages/request!saveRequest.action` + idsStr, qs.stringify(newobj));
};

// 自定义表单编辑请求
export const updateRequestCustomer = (params: {}, header: string, idsStr: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (`${key}` === "approvalNo") {
        newobj[header + ".piv." + `${key}`] = `${params[key]}`;
      } else if (`${key}`.includes("eav_")) {
        newobj[header + ".attrVals['" + `${key}` + "']"] = `${params[key]}`;
      } else if (`${key}` === "templateType") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateName") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "templateId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isShowBorder") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "isNewForm") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else if (`${key}` === "serviceDirId") {
        newobj["templateDTO" + "." + `${key}`] = `${params[key]}`;
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  }
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  return http.post("" + `/pages/request!updateRequest.action` + idsStr, qs.stringify(newobj));
};

//技术员工作量
export const findCountRequest = params => {
  return http.post("/pages/request!countRequest.action", qs.stringify(params), { loading: false });
};
//工作量按条件查询
export const findRequestFlotPieData = (params, time) => {
  return http.post("/pages/request!requestFlotPieData.action?timeStamp=" + time, qs.stringify(params));
};

//查询自定义模板
export const findAllTemplate = () => {
  return http.post(
    "/pages/template!findAllTemplate.action?templateDTO.templateType=request&templateDTO.serviceDirId=0",
    qs.stringify({})
  );
};
